/**
 *
 */
package cn.changeforyou.web.plugin.page;

/**
 * @md-api
 * 分页从1开始, 不过传0的结果和传1的结果一样
 * @author zhyu
 */
public class LocalThreadPageUtil {

    final static ThreadLocal<Integer> PAGE_NUMBER = new ThreadLocal();

    final static ThreadLocal<Integer> PAGE_SIZE = new ThreadLocal();

    public static Integer getPageNumber() {
        return PAGE_NUMBER.get();
    }

    public static void setPageNumber(Integer pageNumber) {
        PAGE_NUMBER.set(pageNumber);
    }

    public static Integer getPageSize() {
        return PAGE_SIZE.get();
    }

    public static void setPageSize(Integer pageSize) {
        PAGE_SIZE.set(pageSize);
    }
    
    public static void clear() {
        PAGE_NUMBER.remove();
        PAGE_SIZE.remove();
    }
    
    /**
     * 获取mysql limit后面的第一个参数
     * @return
     */
    public static int getMysqlPageParam1(){
        Integer number = PAGE_NUMBER.get();
        if(number == 0) {
            return 0;
        }
        Integer size = PAGE_SIZE.get();
        return (number-1)*size;
    }

    /**
     * 获取mysql limit后面的第一个参数
     * @return
     */
    public static int getMysqlPageParam2(){
        return PAGE_SIZE.get();
    }

}
